<?php

// MODELE ARTICLE

//abstract class Modele {
//
//    protected $mysql;
//
//    public function __construct() {
//        try {
//
//            $this->mysql = new PDO(SERVER, USER, PASSWORD);
//        } catch (PDOException $e) {
//            echo"Erreur de connexion au serveur :<br>" . $e->getMessage() . "<br>";
//        }
//    }
//
//}

class ModeleCommentaire extends Modele {

    // METHODE AFFICHAGE ARTICLE

    public function selectListeCommentaire($commentaires, $contenu) {

        $sql = "SELECT $contenu FROM $commentaires ORDER BY dateHeure DESC";

        $req = $this->mysql->query($sql);

        return $req->fetchAll();
    }

    public function selectUnCommentaire($commentaires, $contenu, $id) {

        $sql = "SELECT $contenu FROM $commentaires WHERE ID=$id";

        $req = $this->mysql->query($sql);

        return $req->fetchAll();
    }

    public function UpdateUnCommentaire($table, $id, $tab) {

        $temp = null;

        for ($x = 0; $x < count($tab); $x++) {
            $temp .= $tab[$x][0] . "='" . $tab[$x][1] . "'";
            if ($x < (count($tab) - 1))
                $temp.=", ";
        }
        $sql = "UPDATE $table SET $temp WHERE ID=$id";

        $req = $this->mysql->query($sql);
    }

    // METHODE SUPPRESSION ARTICLE

    public function supprimerCommentaire($commentaires, $ID) {

        $idArticle = $_GET["idArticle"];
        $sql = "DELETE FROM $commentaires WHERE $ID=$idArticle";

        $req = $this->mysql->query($sql);
    }

}
